package com.newbingo.action;

import com.newbingo.dto.MemberDto;
import com.newbingo.entity.Member;
import com.newbingo.service.imple.IMemberService;
import com.newbingo.service.imple.ITradeRecordService;
import com.newbingo.util.Pager;
import com.opensymphony.xwork2.ActionSupport;
import com.googlecode.jsonplugin.annotations.JSON;

/**
 * 会员历史交易记录action
 * @author ChansonYan
 *
 */
public class TradeRecordAction extends ActionSupport {
	//注入属性
	private ITradeRecordService tradeRecordService;
	private IMemberService memberService;
	//分页查询条件
	private Integer uno;
	private int start;
	private int limit=10;
	private Pager page;
	
	//会员充值提现属性,交易分值、交易类型(充值、提现)
	private Integer score;
	private String tradeType;
	/*
	 * 根据会员ID查询出会员信息，主要查询出会员的余额，供授信账户充值提现
	 */
	private MemberDto memberDto;
	
	//方法判断是否执行成功
	private Boolean success=false;
	
	
	/*****************  操作方法  **************************/    
	/*
	 * 根据会员ID查询出交易记录，并分页显示。返回的page中data为TradeRecordDto泛型
	 */
	public String findByPage(){
		System.out.println(uno);
		page=tradeRecordService.findByPage(start, limit, uno);
		System.out.println(page.getTotalSize());
		success=true;
		return SUCCESS;
	}
	
	/*
	 * 后台点击充值或提现，先进行查询用户余额操作,页面上显示账户余额信息等
	 */
	public String toTrade(){
		memberDto=memberService.findById(uno);
		success=true;
		return SUCCESS;
	}
	
	/*
	 * 保存会员账户交易信息(提现要在前台验证交易金额是否大于账户余额)
	 * tradeType ("提现","充值")
	 */
	public String saveTrade(){
		tradeRecordService.saveTrade(uno, score, tradeType);
		success=true;
		return SUCCESS;
	}
	
	@JSON(serialize=false)
	public ITradeRecordService getTradeRecordService() {
		return tradeRecordService;
	}
	public void setTradeRecordService(ITradeRecordService tradeRecordService) {
		this.tradeRecordService = tradeRecordService;
	}
	
	@JSON(serialize=false)
	public IMemberService getMemberService() {
		return memberService;
	}
	public void setMemberService(IMemberService memberService) {
		this.memberService = memberService;
	}
	
	public Integer getUno() {
		return uno;
	}
	public void setUno(Integer uno) {
		this.uno = uno;
	}
	
	public int getStart() {
		return start;
	}
	public void setStart(int start) {
		this.start = start;
	}
	
	public int getLimit() {
		return limit;
	}
	public void setLimit(int limit) {
		this.limit = limit;
	}
	
	public Pager getPage() {
		return page;
	}
	public void setPage(Pager page) {
		this.page = page;
	}

	@JSON(serialize=false)
	public Integer getScore() {
		return score;
	}
	public void setScore(Integer score) {
		this.score = score;
	}
	
	@JSON(serialize=false)
	public String getTradeType() {
		return tradeType;
	}
	public void setTradeType(String tradeType) {
		this.tradeType = tradeType;
	}

	public MemberDto getMemberDto() {
		return memberDto;
	}
	public void setMemberDto(MemberDto memberDto) {
		this.memberDto = memberDto;
	}

	public Boolean getSuccess() {
		return success;
	}
	public void setSuccess(Boolean success) {
		this.success = success;
	}
	
}
